<!--
 * @Author: zhangjingyu
 * @Date: 2020-10-13 14:12:54
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2020-12-03 10:48:29
 * @FilePath: \vprisk-weifuwu\src\views\SystemMange\userManage.vue
 * @Description: 用户管理
-->

<template>
  <div>
    <el-row class="caliberHierarchy container">
      <el-col style="margin-right:10px;" :span="18" class="content-left">
        <el-row class="handleBox">
          <el-col :span="18">
            <el-button type="primary" @click="addFunc">新增</el-button>
            <el-button type="primary" @click="editFunc">编辑</el-button>
            <el-button type="primary" @click="unlock">解锁</el-button>
            <el-button type="primary" @click="writeOff">注销</el-button>
            <el-button type="primary" @click="authorization('role')"
              >角色授权</el-button
            >
            <el-button type="primary" @click="authorization('pro')"
              >工程授权</el-button
            >
          </el-col>
          <el-col :span="6">
            <div class="handleIconBox">
              <el-popover
                placement="bottom"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="search_porper">
                  <el-form
                    :model="searchForm"
                    ref="searchForm"
                    label-width="80px"
                    label-position="right"
                    size="mini"
                  >
                    <el-form-item label="姓名：">
                      <el-input
                        v-model="searchForm.treeTypeCode"
                        style="width:150px"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="用户名：" prop="treeTypeName">
                      <el-input
                        v-model="searchForm.treeTypeName"
                        style="width:150px"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label="所属机构：" prop="orgId">
                      <el-tooltip
                        :content="searchOrgTip"
                        :disabled="!searchOrgTip"
                        placement="right-end"
                        class="item"
                      >
                        <el-cascader
                          clearable
                          filterable
                          :options="orgList"
                          v-model="searchForm.orgId"
                          :props="{ checkStrictly: true, emitPath: false }"
                          :show-all-levels="false"
                          style="width:150px"
                          ref="searchOrgTree"
                          @change="searchOrgHandle"
                        ></el-cascader>
                      </el-tooltip>
                    </el-form-item>
                    <el-form-item label="口径方案：" prop="caliberProjectName">
                      <el-select
                        v-model="searchForm.caliberProjectName"
                        placeholder="请选择"
                        style="width:150px"
                      >
                        <el-option label="区域一" value="shanghai"></el-option>
                        <el-option label="区域二" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="角色：" prop="treeTypeName">
                      <el-input
                        v-model="searchForm.treeTypeName"
                        style="width:150px"
                      ></el-input>
                    </el-form-item>
                  </el-form>
                  <div style="text-align:center;padding:10px">
                    <el-button type="primary" size="mini">查询</el-button>
                    <el-button
                      size="mini"
                      @click="
                        (searchFF.caliberName = ''), (searchFF.caliberCode = '')
                      "
                      >重置</el-button
                    >
                  </div>
                </div>
                <i
                  class="iconfont icon-sousuo"
                  title="搜索"
                  slot="reference"
                ></i>
              </el-popover>
              <el-popover
                placement="bottom"
                trigger="click"
                popper-class="icon_porper"
              >
                <div class="operation_checkbox">
                  <el-checkbox-group v-model="checkList">
                    <el-checkbox
                      v-for="item in textData"
                      :label="item.label"
                      :key="item.prop"
                      :disabled = "item.disabled"
                      >{{ item.label }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
                <i
                  class="iconfont icon-liebiaoshezhi"
                  title="列表设置"
                  slot="reference"
                ></i>
              </el-popover>
              <i class="iconfont icon-export" title="导出"></i>
              <i class="iconfont icon-import" title="导入"></i>
            </div>
          </el-col>
        </el-row>
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%"
          @row-click="authorizeFor"
        >
          <el-table-column
            width="55"
            type="selection"
            fixed="left"
          ></el-table-column>
          <el-table-column
            prop="userName"
            label="用户名"
            align="center"
            v-if="columnState[0]"
          >
          </el-table-column>
          <el-table-column
            prop="realName"
            label="用户姓名"
            align="center"
            sortable
            v-if="columnState[1]"
          >
          </el-table-column>
          <el-table-column
            prop="orgName"
            label="机构"
            sortable
            v-if="columnState[2]"
          >
          </el-table-column>
          <el-table-column
            prop="useFlag"
            label="状态"
            v-if="columnState[3]"
            :filter-method="(val, row) => row.useFlag === val"
            :filters="[
              { text: '启用', value: '1' },
              { text: '锁定', value: '0' }
            ]"
          >
            <template slot-scope="scope">
              <div v-if="scope.row.useFlag == 1">
                <i class="startState"></i>启用
              </div>
              <div v-if="scope.row.useFlag == 0">
                <i class="unStartState"></i>锁定
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="project[0].projectName"
            label="授权工程"
            sortable
            v-if="columnState[4]"
          >
          </el-table-column>
          <el-table-column
            prop="role[0].roleName"
            label="授权角色"
            sortable
            v-if="columnState[5]"
          >
          </el-table-column>
       
        </el-table>
        <pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @refresh="searchFunc"
      :current="searchForm.page"
      :total="400"
    ></pagination>
      </el-col>
      <el-col :span="5" class="content-right">
        <div class="title">
          <div style="float:left">
            <span class="gun"></span> 为 {{ userName }}授权{{rightButtonFlag=='pro'?'工程':'角色'}}
          </div>
          <div class="handleIconBox" style="width:50px;padding-top:16px" v-if="rightButtonFlag=='role'">
            <i
              class="iconfont icon-export"
              title="导出"
              style="margin-right:15px"
            ></i>
            <i class="iconfont icon-import" title="导入"></i>
          </div>
        </div>
        <el-button
        style="margin:10px"
          type="primary"
          @click="saveRoleOrPro"
          >保存</el-button
        >
        <!-- 角色授权table -->
        <el-table
          ref="roleTable"
          :data="tableDataRole"
          v-if="rightButtonFlag=='role'"
          style="width: 100%"
          class="isRightTable"
          :header-cell-style="$store.state.style.tableHead"
          :cell-style="$store.state.style.tableBody"
        >
          <el-table-column
            width="55"
            type="selection"
            fixed="left"
          ></el-table-column>
          <el-table-column
            prop="roleCode"
            label="角色编号"
          ></el-table-column>
          <el-table-column
            prop="roleName"
            label="角色名称"
          ></el-table-column>
        </el-table>

        <!-- 工程授权table -->
              <el-table
          ref="proTable"
          :data="tableDataPro"
          v-if="rightButtonFlag=='pro'"
          style="width: 100%"
          class="isRightTable"
          :header-cell-style="$store.state.style.tableHead"
          :cell-style="$store.state.style.tableBody"
        >
          <el-table-column
            width="55"
            type="selection"
            fixed="left"
          ></el-table-column>
          <el-table-column
            prop="roleCode"
            label="工程名称 "
          ></el-table-column>
          <el-table-column
            prop="roleName"
            label="数据库用户"
          ></el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-dialog v-dialogDrag
      :title="saveTitles[saveFlg - 1]"
      :visible.sync="addOrEdit"
      top="2%"
    >
      <el-form
        :model="saveForm"
        ref="addTreeForm"
        label-width="150px"
        label-position="right"
        :rules="saveFormRules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户名：" prop="userName">
              <el-input
                v-model="saveForm.userName"
                style="width:200px"
                maxlength="40"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户姓名：" prop="realName">
              <el-input
                v-model="saveForm.realName"
                style="width:200px"
                maxlength="40"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户密码：" prop="password">
              <el-input
                v-model="saveForm.password"
                style="width:200px"
                type="password"
                maxlength="40"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="确认密码：" prop="passwordStr">
              <el-input
                v-model="saveForm.passwordStr"
                style="width:200px"
                type="password"
                maxlength="40"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属机构：" prop="orgId">
              <el-tooltip
                :content="saveOrgTip"
                :disabled="!saveOrgTip"
                placement="top"
                class="item"
              >
                <el-cascader
                  clearable
                  filterable
                  :options="orgList"
                  v-model="saveForm.orgId"
                  :props="{
                    checkStrictly: true,
                    emitPath: false,
                    expendTrigger: 'hover'
                  }"
                  :show-all-levels="false"
                  ref="saveOrgTree"
                  style="width:200px"
                  @change="checkFormOrg"
                ></el-cascader>
              </el-tooltip>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户状态：" prop="status">
              <el-input
                v-model="saveForm.status"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工编号：" prop="empNo">
              <el-input
                v-model="saveForm.empNo"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号：" prop="idcard">
              <el-input
                v-model="saveForm.idcard"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="办公电话：" prop="officePhone">
              <el-input
                v-model="saveForm.officePhone"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="移动电话：" prop="mobilePhone">
              <el-input
                v-model="saveForm.mobilePhone"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="家庭电话：" prop="famliyPhone">
              <el-input
                v-model="saveForm.famliyPhone"
                style="width:200px"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="邮箱地址：" prop="email">
              <el-input v-model="saveForm.email" style="width:200px"></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="机构选择：" prop="email">
              <treeSelect v-model="saveForm.email" style="width:200px" 
              :data = "orgList1"></treeSelect>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addOrEdit = false" v-if="saveFlg != 3"
          >确 定</el-button
        >
        <el-button @click="addOrEdit = false">取 消</el-button>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
import { publicManage } from "@/api/index";

export default {
  data() {
    return {
      userName: "",
      addOrEdit: false, // 新增/编辑/查看弹窗
      saveFlg: 1, // 1:新增，2：编辑，3查看,
      rightButtonFlag:"role",// 区分角色授权（role）和工程授权（pro）
      saveTitles: ["添加用户信息", "编辑用户信息"],
      // 机构树
      orgList: [
        {
          value: "01",
          label: "一级机构",
          children: [{ value: "001", label: "二级机构" }]
        }
      ],
      orgList1: [
        {
          id: "01",
          label: "一级机构",
          children: [{ id: "001", label: "二级机构" }]
        }
      ],
      // search机构树悬停提示
      searchOrgTip: "",
      // save表单机构树悬停提示
      saveOrgTip: "",
      searchForm: {},
      saveForm: {
        operateType:"2",
        userId: "",
        userName: "",
        realName:"",
        password:"",
        passwordStr:"",
        orgId:"",
        orgId_text:"",
        useFlag:"",
        empNo:"",
        idcard:"",
        officePhone:"",
        mobilePhone:"",
        famliyPhone:"",
        email: "",
      },
      saveFormRules: {
        userName: [
          { required: true, message: "该输入项为必输项", trigger: "blur" }
        ],
        realName: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
        ],
        password: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
          {min:6,max:8,message: "密码长度在6-8之间", trigger: "blur" }
          // { validator: this.validPassword, trigger: "blur" },
        ],
        passwordStr:[
          { required: true, message: "该输入项为必输项", trigger: "blur" },
          { validator: this.validPassword, trigger: "blur" },
        ],
        orgId:[
          { required: true, message: "该输入项为必输项", trigger: "blur" },
        ],
        status:[
          { required: true, message: "该输入项为必输项", trigger: "blur" },
        ],
      },
      checkList: [],
      // 完整表头字段&&列属性配置
      textData: [
        { prop: "userName", label: "用户名", align: "center",disabled:true },
        { prop: "realName", label: "用户姓名", sortable: true ,disabled:true},
        { prop: "orgName", label: "机构 ", sortable: true },
        {
          prop: "useFlag",
          label: "状态"
        },
        { prop: "project.projectName", label: "授权工程 ", sortable: true },
        { prop: "role[0].roleName", label: "授权角色", sortable: true }
      ],
      // 获取table的数据
      tableData: [
        {
          userId: "40288dfd72220a74017225a73ec901d0",
          userName: "80100",
          realName: "IES上海分行",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "40288dfd72220a74017225a92f6c01d6",
              roleCode: "ROLE_IES_ORGUSER",
              roleName: "IES分行用户",
              roleDesc: null,
              userId: "40288dfd72220a74017225a73ec901d0",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: []
        },
        {
          userId: "40288dfd72220a74017225a7f10701d4",
          userName: "80300",
          realName: "IES北京分行",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "40288dfd72220a74017225a92f6c01d6",
              roleCode: "ROLE_IES_ORGUSER",
              roleName: "IES分行用户",
              roleDesc: null,
              userId: "40288dfd72220a74017225a7f10701d4",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: []
        },
        {
          userId: "40288dfd73c396d70173c8dd7c4c00c1",
          userName: "BBW",
          realName: "BBW",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "40288dfd73c396d70173c8d17b7a0007",
              roleCode: "ROLE_BBW",
              roleName: "BBW",
              roleDesc: null,
              userId: "40288dfd73c396d70173c8dd7c4c00c1",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: [
            {
              creator: "sysadmin",
              createdTm: 1585270580126,
              modifier: null,
              modifiedTm: null,
              status: "1",
              projectId: "PROJ000006",
              projectName: "PROJ000005",
              moduleCode: "ALM",
              dbUsername: "ALM_ENGINE",
              dbUserpwd: "lc/JGU0IsLtLldqMo+E2hA==",
              remark: null,
              syncCompleteFlag: "N",
              syncFlag: "Y",
              useFlag: "0",
              useSum: 28
            }
          ]
        },
        {
          userId: "40288dfd73946e140173993b684c0025",
          userName: "qingdao_user",
          realName: "青岛用户",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "40288dfd73946e140173993c44c80027",
              roleCode: "ROLE_DMS",
              roleName: "集市管理员",
              roleDesc: null,
              userId: "40288dfd73946e140173993b684c0025",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: []
        },
        {
          userId: "40288dfd734fed1601736eedd17409ab",
          userName: "sysadbc",
          realName: "农发总行管理员",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "40288dfd734fed1601736ed9cbc908e1",
              roleCode: "ROLE_ADBC",
              roleName: "农发总行管理员",
              roleDesc: null,
              userId: "40288dfd734fed1601736eedd17409ab",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: []
        },
        {
          userId: "40288114349d8a7701349d9bc3580003",
          userName: "sysadmin",
          realName: "sys",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "402881b339752b450139752df0950001",
              roleCode: "ROLE_sysadmin",
              roleName: "sysadmin",
              roleDesc: null,
              userId: "40288114349d8a7701349d9bc3580003",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288deb6fc5bfb401703804ffd6005e",
              roleCode: "ROLE_TC_1001",
              roleName: "总行头寸管理员",
              roleDesc: null,
              userId: "40288114349d8a7701349d9bc3580003",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288deb6fc5bfb40170380582c00061",
              roleCode: "ROLE_TC_1002",
              roleName: "分行头寸管理员",
              roleDesc: null,
              userId: "40288114349d8a7701349d9bc3580003",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288deb6fc5bfb4017038065c6f0064",
              roleCode: "ROLE_TC_1003",
              roleName: "支行头寸管理员",
              roleDesc: null,
              userId: "40288114349d8a7701349d9bc3580003",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: [
            {
              creator: "sysadmin",
              createdTm: 1585270580126,
              modifier: null,
              modifiedTm: null,
              status: "1",
              projectId: "PROJ000006",
              projectName: "PROJ000005",
              moduleCode: "ALM",
              dbUsername: "ALM_ENGINE",
              dbUserpwd: "lc/JGU0IsLtLldqMo+E2hA==",
              remark: null,
              syncCompleteFlag: "N",
              syncFlag: "Y",
              useFlag: "0",
              useSum: 28
            }
          ]
        },
        {
          userId: "40288deb6ac49e21016ac4d72b32015e",
          userName: "vprisk",
          realName: "泛鹏售前",
          useFlag: "1",
          orgName: "泛鹏银行",
          org: {
            creator: null,
            createdTm: null,
            modifier: "sysadmin",
            modifiedTm: 1583302930007,
            status: "1",
            orgId: "4028815d3929aeac013929bf83050001",
            orgCode: "8000",
            orgName: "泛鹏银行",
            orgLevel: 0,
            parentOrgan: null,
            orgSeq: "000",
            orgType: null,
            startDate: 1538323200000,
            endDate: null,
            sortNo: null,
            leafFlag: "1",
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: "0"
          },
          role: [
            {
              roleId: "402881b339752b450139752df0950001",
              roleCode: "ROLE_sysadmin",
              roleName: "sysadmin",
              roleDesc: null,
              userId: "40288deb6ac49e21016ac4d72b32015e",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          project: []
        },
        {
          userId: "40288dfd74233bb101742892d7810000",
          userName: "zztest",
          realName: "zztest",
          useFlag: "1",
          orgName: "上海分行",
          org: {
            creator: "sysadmin",
            createdTm: 1582697467116,
            modifier: null,
            modifiedTm: null,
            status: "1",
            orgId: "40288dfd707fe2ce0170801ecd370013",
            orgCode: "80000200",
            orgName: "上海分行",
            orgLevel: 1,
            parentOrgan: {
              creator: null,
              createdTm: null,
              modifier: "sysadmin",
              modifiedTm: 1583302930007,
              status: "1",
              orgId: "4028815d3929aeac013929bf83050001",
              orgCode: "8000",
              orgName: "泛鹏银行",
              orgLevel: 0,
              parentOrgan: null,
              orgSeq: "000",
              orgType: null,
              startDate: 1538323200000,
              endDate: null,
              sortNo: null,
              leafFlag: "1",
              remark: null,
              orgAddr: null,
              zipCode: null,
              linkman: null,
              linktel: null,
              email: null,
              weburl: null,
              orgDegree: null,
              orgDeptFlag: "0"
            },
            orgSeq: "000002",
            orgType: null,
            startDate: 1582697467000,
            endDate: null,
            sortNo: null,
            leafFlag: null,
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: null
          },
          role: [
            {
              roleId: "40288dfd72220a74017225a92f6c01d6",
              roleCode: "ROLE_IES_ORGUSER",
              roleName: "IES分行用户",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288dfd73c396d70173c8d17b7a0007",
              roleCode: "ROLE_BBW",
              roleName: "BBW",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          defaultProps: {
            children: "children",
            label: "label"
          },
          treeData: [],
          project: []
        },
        {
          userId: "40288dfd74233bb101742892d7810000",
          userName: "zztest",
          realName: "zztest",
          useFlag: "1",
          orgName: "上海分行",
          org: {
            creator: "sysadmin",
            createdTm: 1582697467116,
            modifier: null,
            modifiedTm: null,
            status: "1",
            orgId: "40288dfd707fe2ce0170801ecd370013",
            orgCode: "80000200",
            orgName: "上海分行",
            orgLevel: 1,
            parentOrgan: {
              creator: null,
              createdTm: null,
              modifier: "sysadmin",
              modifiedTm: 1583302930007,
              status: "1",
              orgId: "4028815d3929aeac013929bf83050001",
              orgCode: "8000",
              orgName: "泛鹏银行",
              orgLevel: 0,
              parentOrgan: null,
              orgSeq: "000",
              orgType: null,
              startDate: 1538323200000,
              endDate: null,
              sortNo: null,
              leafFlag: "1",
              remark: null,
              orgAddr: null,
              zipCode: null,
              linkman: null,
              linktel: null,
              email: null,
              weburl: null,
              orgDegree: null,
              orgDeptFlag: "0"
            },
            orgSeq: "000002",
            orgType: null,
            startDate: 1582697467000,
            endDate: null,
            sortNo: null,
            leafFlag: null,
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: null
          },
          role: [
            {
              roleId: "40288dfd72220a74017225a92f6c01d6",
              roleCode: "ROLE_IES_ORGUSER",
              roleName: "IES分行用户",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288dfd73c396d70173c8d17b7a0007",
              roleCode: "ROLE_BBW",
              roleName: "BBW",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          defaultProps: {
            children: "children",
            label: "label"
          },
          treeData: [],
          project: []
        },
        {
          userId: "40288dfd74233bb101742892d7810000",
          userName: "zztest",
          realName: "zztest",
          useFlag: "0",
          orgName: "上海分行",
          org: {
            creator: "sysadmin",
            createdTm: 1582697467116,
            modifier: null,
            modifiedTm: null,
            status: "1",
            orgId: "40288dfd707fe2ce0170801ecd370013",
            orgCode: "80000200",
            orgName: "上海分行",
            orgLevel: 1,
            parentOrgan: {
              creator: null,
              createdTm: null,
              modifier: "sysadmin",
              modifiedTm: 1583302930007,
              status: "1",
              orgId: "4028815d3929aeac013929bf83050001",
              orgCode: "8000",
              orgName: "泛鹏银行",
              orgLevel: 0,
              parentOrgan: null,
              orgSeq: "000",
              orgType: null,
              startDate: 1538323200000,
              endDate: null,
              sortNo: null,
              leafFlag: "1",
              remark: null,
              orgAddr: null,
              zipCode: null,
              linkman: null,
              linktel: null,
              email: null,
              weburl: null,
              orgDegree: null,
              orgDeptFlag: "0"
            },
            orgSeq: "000002",
            orgType: null,
            startDate: 1582697467000,
            endDate: null,
            sortNo: null,
            leafFlag: null,
            remark: null,
            orgAddr: null,
            zipCode: null,
            linkman: null,
            linktel: null,
            email: null,
            weburl: null,
            orgDegree: null,
            orgDeptFlag: null
          },
          role: [
            {
              roleId: "40288dfd72220a74017225a92f6c01d6",
              roleCode: "ROLE_IES_ORGUSER",
              roleName: "IES分行用户",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            },
            {
              roleId: "40288dfd73c396d70173c8d17b7a0007",
              roleCode: "ROLE_BBW",
              roleName: "BBW",
              roleDesc: null,
              userId: "40288dfd74233bb101742892d7810000",
              supRoleId: null,
              mgrRole: [],
              roleMutex: []
            }
          ],
          defaultProps: {
            children: "children",
            label: "label"
          },
          treeData: [],
          project: []
        }
      ],
      tableDataPro:[
        {
          creator: "sysadmin",
          createdTm: 1596802038650,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288dfd73c396d70173c8d17b7a0007",
          roleCode: "ROLE_BBW",
          roleName: "BBW",
          roleDesc: "BBW",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
      ],
      tableDataRole: [
        {
          creator: "sysadmin",
          createdTm: 1596802038650,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288dfd73c396d70173c8d17b7a0007",
          roleCode: "ROLE_BBW",
          roleName: "BBW",
          roleDesc: "BBW",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1589769744235,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288dfd72220a74017225a92f6c01d6",
          roleCode: "ROLE_IES_ORGUSER",
          roleName: "IES分行用户",
          roleDesc: null,
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: null,
          createdTm: null,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "402881b339752b450139752df0950001",
          roleCode: "ROLE_sysadmin",
          roleName: "sysadmin",
          roleDesc: "sysadmin",
          roleType: "1",
          admFlag: "0",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1595292634056,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288dfd734fed1601736ed9cbc908e1",
          roleCode: "ROLE_ADBC",
          roleName: "农发总行管理员",
          roleDesc: null,
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1581487850176,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288deb6fc5bfb40170380582c00061",
          roleCode: "ROLE_TC_1002",
          roleName: "分行头寸管理员",
          roleDesc: "分行头寸管理员",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1581487816661,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288deb6fc5bfb401703804ffd6005e",
          roleCode: "ROLE_TC_1001",
          roleName: "总行头寸管理员",
          roleDesc: "总行头寸管理员",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1581487905900,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288deb6fc5bfb4017038065c6f0064",
          roleCode: "ROLE_TC_1003",
          roleName: "支行头寸管理员",
          roleDesc: "支行头寸管理员",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        },
        {
          creator: "sysadmin",
          createdTm: 1596003730630,
          modifier: null,
          modifiedTm: null,
          status: "1",
          roleId: "40288dfd73946e140173993c44c80027",
          roleCode: "ROLE_DMS",
          roleName: "集市管理员",
          roleDesc: "集市管理员",
          roleType: null,
          admFlag: "2",
          roleLevel: null,
          mgrRoleNames: null
        }
      ],
     
    };
  },
  created() {
    this.checkListInit();
    console.log(this.tableData, "模拟数据");
  },
  mounted() {
    
  },
  computed: {
    columnState() {
      console.log(this.checkList);
      let arr = [],
        arr1 = this.textData,
        arr2 = this.checkList;
      for (let i = 0; i < arr1.length; i++) {
        let flg = false;
        for (let j = 0; j < arr2.length; j++) {
          if (arr1[i].label === arr2[j]) {
            flg = true;
          }
        }
        arr.push(flg);
      }
      return arr;
    },
  },
  mounted() {
    this.getTableList();
  },
  watch: {},
  methods: {
    // 获取表格数据
    getTableList(){
      // 默认传入第一行的数据到右侧，默认为授权角色
      this.authorizeFor(this.tableData[0])
    },
    // 处理搜索机构框点击选中隐藏,鼠标悬停提示
    searchOrgHandle() {
      this.$refs.searchOrgTree.dropDownVisible = false;
      let node = this.$refs.searchOrgTree.getCheckedNodes();
      if (node.length != 0) {
        this.searchOrgTip = node[0].label;
      } else {
        this.searchOrgTip = "";
      }
    },
    // 处理save表单机构选中事件
    checkFormOrg() {
      let node = this.$refs.saveOrgTree.getCheckedNodes();
      this.$refs.saveOrgTree.dropDownVisible = false; // 隐藏模态框
      if (node.length != 0) {
        this.saveForm.orgName = node[0].label;
        this.saveOrgTip = node[0].label;
      } else {
        this.saveForm.orgName = "";
        this.saveOrgTip = "";
      }
    },
    // 两个密码校验
    validPassword(rule,value,callback){
      if(this.saveForm.password===this.saveForm.passwordStr){
        callback()
      }else{callback(new Error('两次输入密码不一致'))}
    },
    checkListInit() {
      this.checkList = this.textData.map(v => {
        return v.label;
      });
    },
    // 查询
    searchFunc(){
      let data = this.searchForm
      console.log(data)
    },
    addFunc() {
      this.saveFlg = 1;
      for (let k in this.saveForm) {
        this.saveForm[k] = "";
      }
      this.addOrEdit = true;
    },
    editFunc() {
      this.saveFlg = 2;
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行修改");
      }
      let row = selection[0];
      let form = {...row
      };
      this.saveForm = form;
      this.addOrEdit = true;
    },
    unlock() {
      
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要解锁的用户");
      }
      this.$confirm(
        "你确定要解锁中的用户吗?！",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          this.$message.success("解锁成功");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消解锁"
          });
        });
    },
    writeOff() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要注销的用户");
      }
      this.$confirm(
        "你确定要注销选中的用户吗，注销后该用户将不能使用，请慎重！",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          this.$message.success("注销成功");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消注销"
          });
        });
    },
    handleNodeClick() {
      let nodes = this.$refs.caliberConfigTree.getCheckedNodes();
      console.log(nodes);
    },
    caliberProjectNameFormatter(row) {
      return row.caliberProject.caliberProjectName;
    },
    getList() {
      publicManage.query("我的参数").then(res => {
        console.log(res);
      });
    },
    // 点击表格右侧显示为xx授权
    authorizeFor(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
      this.userName = row.userName;
    },

    // 右侧角色或工程的保存
    saveRoleOrPro(){

    },
    authorization(str) {
      this.rightButtonFlag = str
      let checked = this.$refs.multipleTable.selection;
      if (checked.length < 1) {
        return this.$message.warning("请选择一条数据");
      } else if (checked.length > 1) {
        return this.$message.warning("只能选择一条数据");
      } else {
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchForm.szie = val
      this.searchFunc()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.searchForm.page = val
      this.searchFunc()
    },
   
  }
};
</script>

<style lang="scss" scoped>
</style>